import VueRouter from "vue-router";
import Vue from "vue";

Vue.use(VueRouter);
import routes from "./routes";

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;

VueRouter.prototype.push = function (value, resolve, rejected) {
  if (resolve && rejected) {
    originPush.call(this, value, resolve, rejected);
  } else {
    originPush.call(
      this,
      value,
      () => {},
      () => {}
    );
  }
};

VueRouter.prototype.replace = function (value, resolve, rejected) {
  if (resolve && rejected) {
    originReplace.call(this, value, resolve, rejected);
  } else {
    originReplace.call(
      this,
      value,
      () => {},
      () => {}
    );
  }
};

export default new VueRouter({
  mode: "hash",
  routes,
  scrollBehavior(to, from, savedPosition) {
    return { y: 0 };
  },
});
